package com.ctsi.ssdc.admin.repository;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import com.ctsi.ssdc.admin.domain.CscpUserDetail;
import com.ctsi.ssdc.admin.domain.CscpUserDetailExample;
import com.ctsi.ssdc.admin.domain.CscpUserDetailLike;
import com.ctsi.ssdc.admin.domain.dto.CscpUserDetailDTO;
import com.ctsi.ssdc.database.annotation.InjectByDataBaseType;
import com.ctsi.ssdc.database.enums.EnumDatabaseName;

/**
 * @author MyBatis Generator
*/
@InjectByDataBaseType(includes= {EnumDatabaseName.ORACLE})
public interface CscpUserDetailRepository {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @SelectProvider(type=CscpUserDetailSqlProvider.class, method="countByExample")
    long countByExample(CscpUserDetailExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @DeleteProvider(type=CscpUserDetailSqlProvider.class, method="deleteByExample")
    int deleteByExample(CscpUserDetailExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @Delete({
        "delete from cscp_user_detail",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @Insert({
        "insert into cscp_user_detail (user_id, family_name, ",
        "name, mobile, email, ",
        "img_path, last_login, ",
        "disc_title, disc_detail, ",
        "register_time)",
        "values (#{userId,jdbcType=INTEGER}, #{familyName,jdbcType=VARCHAR}, ",
        "#{name,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ",
        "#{imgPath,jdbcType=VARCHAR}, #{lastLogin,jdbcType=TIMESTAMP}, ",
        "#{discTitle,jdbcType=VARCHAR}, #{discDetail,jdbcType=VARCHAR}, ",
        "#{registerTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true, keyProperty="id")
    int insert(CscpUserDetail record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @InsertProvider(type=CscpUserDetailSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true, keyProperty="id")
    int insertSelective(CscpUserDetail record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @SelectProvider(type=CscpUserDetailSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<CscpUserDetail> selectByExample(CscpUserDetailExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @Select({
        "select",
        "id, user_id, family_name, name, mobile, email, img_path, last_login, disc_title, ",
        "disc_detail, register_time",
        "from cscp_user_detail",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP)
    })
    CscpUserDetail selectByPrimaryKey(Integer id);
    
    @Select({
        "select",
        "a.id, a.user_id, family_name, name, mobile, email, img_path, last_login, disc_title, ",
        "disc_detail, register_time, u.username",
        "from cscp_user u, cscp_user_detail a, cscp_user_work_group b",
        "where u.id = a.user_id and a.user_id = b.user_id and b.group_id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
    })
    List<CscpUserDetail> selectByWorkGroupId(Integer id);
    
    @Select({
        "select",
        "b.id, b.user_id, a.username, family_name, name, mobile, email, img_path, last_login, disc_title, ",
        "disc_detail, register_time",
        "from cscp_user a, cscp_user_detail b",
        "where a.id = b.user_id",
        "and b.user_id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
    })
    CscpUserDetail selectByUserId(Integer userId);
    
    
    @Select({
        "select",
        "b.id, b.user_id, a.username, family_name, name, mobile, email, img_path, last_login, disc_title, ",
        "disc_detail, register_time",
        "from cscp_user a, cscp_user_detail b, cscp_user_org c",
        "where a.id = b.user_id and a.id = c.user_id"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
    })
    List<CscpUserDetail> selectByOrgs();
    

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @UpdateProvider(type=CscpUserDetailSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") CscpUserDetail record, @Param("example") CscpUserDetailExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @UpdateProvider(type=CscpUserDetailSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") CscpUserDetail record, @Param("example") CscpUserDetailExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @UpdateProvider(type=CscpUserDetailSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CscpUserDetail record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @Update({
        "update cscp_user_detail",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "family_name = #{familyName,jdbcType=VARCHAR},",
          "name = #{name,jdbcType=VARCHAR},",
          "mobile = #{mobile,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "img_path = #{imgPath,jdbcType=VARCHAR},",
          "last_login = #{lastLogin,jdbcType=TIMESTAMP},",
          "disc_title = #{discTitle,jdbcType=VARCHAR},",
          "disc_detail = #{discDetail,jdbcType=VARCHAR},",
          "register_time = #{registerTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(CscpUserDetail record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cscp_user_detail
     *
     * @mbg.generated Mon Apr 23 08:56:34 CST 2018
     */
    @SelectProvider(type=CscpUserDetailSqlProvider.class, method="selectByExampleWithPage")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="family_name", property="familyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="img_path", property="imgPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login", property="lastLogin", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="disc_title", property="discTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="disc_detail", property="discDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="register_time", property="registerTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<CscpUserDetail> selectByExamplewithPage(CscpUserDetailExample example);

    @Results({
        @Result(column="last_login", property="lastLogin"),
        @Result(column="mobile", property="mobile"),
        @Result(column="disc_title", property="discTitle"),
        @Result(column="register_time", property="registerTime"),
        @Result(column="user_id", property="userId"),
        @Result(column="img_path", property="imgPath"),
        @Result(column="name", property="name"),
        @Result(column="disc_detail", property="discDetail"),
        @Result(column="id", property="id"),
        @Result(column="family_name", property="familyName"),
        @Result(column="email", property="email"),
        @Result(column="username", property="username"),
        @Result(column="roleNames", property="roleNames"),
        @Result(column="roleIds", property="roleIds")

    })
	@SelectProvider(type=CscpUserDetailSqlProvider.class, method="queryUserDetail")
	List<CscpUserDetailDTO> queryUserDetail(CscpUserDetailLike cscpUserDetailLike, String orderby);

   /* @Results({
            @Result(column="last_login", property="lastLogin"),
            @Result(column="mobile", property="mobile"),
            @Result(column="disc_title", property="discTitle"),
            @Result(column="register_time", property="registerTime"),
            @Result(column="user_id", property="userId"),
            @Result(column="img_path", property="imgPath"),
            @Result(column="name", property="name"),
            @Result(column="disc_detail", property="discDetail"),
            @Result(column="id", property="id"),
            @Result(column="family_name", property="familyName"),
            @Result(column="email", property="email"),
            @Result(column="username", property="username"),
            @Result(column="roleNames", property="roleNames"),
            @Result(column="roleIds", property="roleIds")

    })
    @SelectProvider(type=CscpUserDetailSqlProvider.class, method="queryUserDetailPreventSQLAttack")
    List<CscpUserDetailDTO> queryUserDetailPreventSQLAttack(String usernameLike,
            String familyNameLike,
            String nameLike,
            String mobileLike,
            String emailLike,
            String discTitleLike,
            String discDetailLike,
            String orderby);*/

    @Results({
            @Result(column="last_login", property="lastLogin"),
            @Result(column="mobile", property="mobile"),
            @Result(column="disc_title", property="discTitle"),
            @Result(column="register_time", property="registerTime"),
            @Result(column="user_id", property="userId"),
            @Result(column="img_path", property="imgPath"),
            @Result(column="name", property="name"),
            @Result(column="disc_detail", property="discDetail"),
            @Result(column="id", property="id"),
            @Result(column="family_name", property="familyName"),
            @Result(column="email", property="email"),
            @Result(column="username", property="username"),
            @Result(column="roleNames", property="roleNames"),
            @Result(column="roleIds", property="roleIds")

    })
    @Select("<script> select cscp_user.username " +
            "        , cscp_user_detail.id as id " +
            "        , cscp_user_detail.user_id " +
            "        , cscp_user_detail.family_name " +
            "        , cscp_user_detail.name " +
            "        , cscp_user_detail.mobile " +
            "        , cscp_user_detail.email " +
            "        , cscp_user_detail.img_path " +
            "        , cscp_user_detail.last_login " +
            "        , cscp_user_detail.disc_title " +
            "        , cscp_user_detail.disc_detail " +
            "        , cscp_user_detail.register_time  " +
            "          from cscp_user  " +
            "        left JOIN cscp_user_detail on cscp_user.id=cscp_user_detail.user_id where 1=1 " +
            " <if test=\"usernameLike != null and usernameLike != '' \" >" +
            " and cscp_user.username like  concat('%',#{usernameLike},'%') " +
            " </if>" +

            " <if test=\"familyNameLike != null and familyNameLike != '' \" >" +
            " or cscp_user_detail.family_name like  concat('%',#{familyNameLike},'%') " +
            " </if>" +

            " <if test=\"nameLike != null and nameLike != '' \" >" +
            " or cscp_user_detail.name like  concat('%',#{nameLike},'%') " +
            " </if>" +

            " <if test=\"mobileLike != null and mobileLike != '' \" >" +
            " or cscp_user_detail.mobile like  concat('%',#{mobileLike},'%') " +
            " </if>" +

            " <if test=\"emailLike != null and emailLike != '' \" >" +
            " or cscp_user_detail.email like  concat('%',#{emailLike},'%') " +
            " </if>" +

            " <if test=\"discTitleLike != null and discTitleLike != '' \" >" +
            " or cscp_user_detail.disc_title like  concat('%',#{discTitleLike},'%') " +
            " </if>" +

            " <if test=\"discDetailLike != null and discDetailLike != '' \" >" +
            " or cscp_user_detail.disc_detail like  concat('%',#{discDetailLike},'%') " +
            " </if>" +

            " <if test=\"orderby != null and orderby != '' \" >" +
            " order by   #{orderby} " +
            " </if>" +

            "" +
            "</script>"

    )
//            "or cscp_user_detail.family_name like '%#{familyNameLike}%' " )
//            "ORDER BY #{orderby} ")
    List<CscpUserDetailDTO> queryUserDetailPreventSQLAttack(
            @Param("usernameLike")String usernameLike,
            @Param("familyNameLike")String familyNameLike,
            @Param("nameLike")String nameLike,
            @Param("mobileLike")String mobileLike,
            @Param("emailLike")String emailLike,
            @Param("discTitleLike")String discTitleLike,
            @Param("discDetailLike")String discDetailLike,
            @Param("orderby")String orderby
    );
    
    @Deprecated
    @Results({
        @Result(column="last_login", property="lastLogin"),
        @Result(column="mobile", property="mobile"),
        @Result(column="disc_title", property="discTitle"),
        @Result(column="register_time", property="registerTime"),
        @Result(column="user_id", property="userId"),
        @Result(column="img_path", property="imgPath"),
        @Result(column="name", property="name"),
        @Result(column="disc_detail", property="discDetail"),
        @Result(column="id", property="id"),
        @Result(column="family_name", property="familyName"),
        @Result(column="email", property="email"),
        @Result(column="username", property="username"),
    })
	@SelectProvider(type=CscpUserDetailSqlProvider.class, method="queryUserDetailByUserId")
	List<CscpUserDetailDTO> queryUserDetailByUserId(String userid, String orderby);
    
    @Results({
        @Result(column="last_login", property="lastLogin"),
        @Result(column="mobile", property="mobile"),
        @Result(column="disc_title", property="discTitle"),
        @Result(column="register_time", property="registerTime"),
        @Result(column="user_id", property="userId"),
        @Result(column="img_path", property="imgPath"),
        @Result(column="name", property="name"),
        @Result(column="disc_detail", property="discDetail"),
        @Result(column="id", property="id"),
        @Result(column="family_name", property="familyName"),
        @Result(column="email", property="email"),
        @Result(column="username", property="username"),
    })
    @Select({"select u.username, d.id as id, d.user_id as user_id,",
    		"family_name, name, mobile, email, img_path, last_login,", 
    		"disc_title, disc_detail, register_time",
    		"from cscp_user u, cscp_user_detail d",
    		"where u.id = d.user_id and u.id=#{userId,jdbcType=INTEGER}"})
    CscpUserDetailDTO queryByUserId(Integer userId);
	
}